package com.yf.exam.modules.paper.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.utils.BeanMapper;
import com.yf.exam.modules.exam.dto.request.ExamFaceCheckReqDTO;
import com.yf.exam.modules.paper.dto.PaperCaptureDTO;
import com.yf.exam.modules.paper.dto.request.PaperCaptureReqDTO;
import com.yf.exam.modules.paper.dto.response.CaptureRespDTO;
import com.yf.exam.modules.paper.entity.PaperCapture;
import com.yf.exam.modules.paper.service.PaperCaptureService;
import com.yf.system.modules.user.dto.response.FaceCheckRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* <p>
* 试卷考题控制器
* </p>
*
* @author 聪明笨狗
* @since 2020-09-19 22:30
*/
@Api(tags={"试卷考题"})
@RestController
@RequestMapping("/api/paper/capture")
public class PaperCaptureController extends BaseController {

    @Autowired
    private PaperCaptureService baseService;

    /**
    * 添加或修改
    * @param reqDTO
    * @return
    */
    @ApiOperation(value = "添加或修改")
    @PostMapping("/save")
    public ApiRest<CaptureRespDTO> save(@RequestBody PaperCaptureReqDTO reqDTO) {
        CaptureRespDTO respDTO = baseService.save(reqDTO);
        return super.success(respDTO);
    }


    /**
     * 查找列表，每次最多返回200条数据
     * @param reqDTO
     * @return
     */
    @RequiresPermissions("exam:list")
    @ApiOperation(value = "查找列表")
    @PostMapping("/list")
    public ApiRest<List<PaperCaptureDTO>> list(@RequestBody PaperCaptureDTO reqDTO) {

        //分页查询并转换
        QueryWrapper<PaperCapture> wrapper = new QueryWrapper<>();

        wrapper.lambda().eq(PaperCapture::getPaperId, reqDTO.getPaperId());

        //转换并返回
        List<PaperCapture> list = baseService.list(wrapper);

        //转换数据
        List<PaperCaptureDTO> dtoList = BeanMapper.mapList(list, PaperCaptureDTO.class);

        return super.success(dtoList);
    }


    /**
     * 人脸认证
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "人脸认证进入考试")
    @PostMapping("/face-check")
    public ApiRest<FaceCheckRespDTO> faceCheck(@RequestBody ExamFaceCheckReqDTO reqDTO) {
        FaceCheckRespDTO respDTO = baseService.faceCheck(reqDTO);
        return super.success(respDTO);
    }
}
